Conditions | 3 |
Total Lines | 21 |
Code Lines | 12 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | import { BEditaApiClient, ApiClientConfig } from './bedita-api-client'; |
||
13 | |||
14 | /** |
||
15 | * Get an API client already created or try to create new one. |
||
16 | * If a client registered with `name` is found then returns it. |
||
17 | * |
||
18 | * @param name The name to use for register the API client |
||
19 | * @param config The configuration to use for create new client. |
||
20 | */ |
||
21 | public static get(name: string, config?: ApiClientConfig): BEditaApiClient { |
||
22 | if (this.has(name)) { |
||
23 | return this.#registry[name]; |
||
24 | } |
||
25 | |||
26 | if (!config || !config.baseUrl) { |
||
27 | throw new Error('Missing required API configuration'); |
||
28 | } |
||
29 | |||
30 | config.name = name; |
||
31 | this.#registry[name] = new BEditaApiClient(config); |
||
32 | |||
33 | return this.#registry[name]; |
||
34 | } |
||
62 |